package worldinruin.resources;

import java.awt.Image;
import java.util.HashMap;

import javax.swing.ImageIcon;

import worldinruin.core.IType;
import worldinruin.core.imp.ResourceTypes;
import worldinruin.core.imp.buildings.BuildingTypes;
import worldinruin.core.imp.soldiers.SoldierTypes;
import worldinruin.core.imp.tilemodels.TileTypes;

public class IconMap {
	
	private HashMap<IType, ImageIcon> iconMap = new HashMap<IType, ImageIcon>();
	private static IconMap instance;
	
	/**
	 * Creates a map with all icons used.
	 */
	private IconMap () {
		iconMap.put(TileTypes.GRASSTILE, new ImageIcon("src/worldinruin/resources/images/grassTile.jpg"));
		iconMap.put(TileTypes.STONETILE, new ImageIcon("src/worldinruin/resources/images/stoneTile.jpg"));
		iconMap.put(TileTypes.FERTILETILE, new ImageIcon("src/worldinruin/resources/images/fertileTile2.jpg"));
		iconMap.put(TileTypes.FORESTTILE, new ImageIcon("src/worldinruin/resources/images/treeTile.jpg"));
		iconMap.put(TileTypes.IRONTILE, new ImageIcon("src/worldinruin/resources/images/ironTile.jpg"));
		
		iconMap.put(SoldierTypes.ARCHER, new ImageIcon("src/worldinruin/resources/images/archerIcon.jpg"));
		iconMap.put(SoldierTypes.CAVALIER, new ImageIcon("src/worldinruin/resources/images/cavalierIcon.jpg"));
		iconMap.put(SoldierTypes.CATAPULT, new ImageIcon("src/worldinruin/resources/images/catapultIcon.jpg"));
		iconMap.put(SoldierTypes.SWORDSMAN, new ImageIcon("src/worldinruin/resources/images/swordIcon.jpg"));
		iconMap.put(SoldierTypes.TROOP, new ImageIcon("src/worldinruin/resources/images/troopIcon.jpg"));
		
		iconMap.put(BuildingTypes.BARRACK, new ImageIcon("src/worldinruin/resources/images/barrackTile.jpg"));
		iconMap.put(BuildingTypes.CITY, new ImageIcon("src/worldinruin/resources/images/cityTile.jpg"));
		iconMap.put(BuildingTypes.FARM, new ImageIcon("src/worldinruin/resources/images/farmTile.jpg"));
		iconMap.put(BuildingTypes.IRONMINE, new ImageIcon("src/worldinruin/resources/images/ironMineTile.jpg"));
		iconMap.put(BuildingTypes.SAWMILL, new ImageIcon("src/worldinruin/resources/images/sawmillTile.jpg"));
		iconMap.put(BuildingTypes.STONEMINE, new ImageIcon("src/worldinruin/resources/images/stoneMineTile.jpg"));
		iconMap.put(BuildingTypes.CITYICON, new ImageIcon("src/worldinruin/resources/images/cityIcon"));

		iconMap.put(ResourceTypes.WOOD, new ImageIcon("src/worldinruin/resources/images/woodIcon.jpg"));
		iconMap.put(ResourceTypes.STONE, new ImageIcon("src/worldinruin/resources/images/stoneIcon.jpg"));
		iconMap.put(ResourceTypes.FOOD, new ImageIcon("src/worldinruin/resources/images/meatIcon.jpg"));
		iconMap.put(ResourceTypes.IRON, new ImageIcon("src/worldinruin/resources/images/ironIcon.jpg"));
		
		iconMap.put(ResourceTypes.WALLPAPER, new ImageIcon("src/worldinruin/resources/images/wirpaper.jpg"));
		iconMap.put(ResourceTypes.ICON, new ImageIcon("src/worldinruin/resources/images/WIRlogo2.jpg"));
	}

	/**
	 * Gets a single instance of IconMap.
	 * @return Single instance of IconMap.
	 */
	public static IconMap getInstance() {
		if (instance == null) {
			instance = new IconMap();
		}
		
		return instance;
	}
	
	/**
	 * Gets icon.
	 * @param i Type to get.
	 * @return Icon.
	 */
	public ImageIcon getIcon(IType i) {
		return iconMap.get(i);
	}

	/**
	 * Gets icon.
	 * @param i Type to get.
	 * @param width Icon's width.
	 * @param height Icon's height.
	 * @return Icon.
	 */
	public ImageIcon getIcon(IType i, int width, int height) {
		return new ImageIcon(iconMap.get(i).getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH));
	}
	
	/**
	 * Gets a scaled icon.
	 * @param i Type to get.
	 * @param width Icon's width.
	 * @param height Icon's height.
	 * @return Icon.
	 */
	public ImageIcon getScaledIcon(ImageIcon i, int width, int height) {
		return new ImageIcon(i.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH));
	}
	
}
